package com.devops.admin.util;

import cn.hutool.core.util.StrUtil;
import com.devops.admin.model.DOSResource;
import com.devops.admin.po.DOSResourcePo;
import com.devops.admin.vo.DOSResourceVo;
import io.lettuce.core.RedisClient;
import io.lettuce.core.RedisURI;

/**
 * @ClassName LettuceRedisUtils
 * @Description TODO
 * @Author heyabo
 * @Date 2022/9/22 09:05
 * @Version 1.0
 **/
public class LettuceRedisUtils {

    /**
     * @Author heyabo
     * @Description 获取RedisURI
     * @Date 14:09 2022/9/21
     * @Param []
     * @return RedisURI
     **/
    public static RedisClient getRedisUri(DOSResource resource, Integer dataBase){
        RedisURI redisURI;
        if (StrUtil.isNotBlank(resource.getPassword())){
            redisURI = RedisURI.Builder.redis(resource.getIp())
                    .withPort(Integer.parseInt(resource.getPort()))
                    .withPassword(resource.getPassword())
                    .withDatabase(dataBase)
                    .build();
        }else {
            redisURI = RedisURI.Builder.redis(resource.getIp())
                    .withPort(Integer.parseInt(resource.getPort()))
                    .withDatabase(dataBase)
                    .build();
        }

        return RedisClient.create(redisURI);
    }

}
